Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
The tapable package provides a collection of classes that can be used to add hooks into a plugin system. These hooks can be used to intercept and modify the behavior of certain functions or events, allowing for a highly customizable and extensible architecture. It is commonly used in webpack's plugin system but can be used in any JavaScript project to add similar plugin capabilities.
SyncHook
SyncHook allows for synchronous execution of multiple functions. It is useful when you need to ensure that hooks are executed in the order they were added.
const { SyncHook } = require('tapable');
const hook = new SyncHook(['arg1', 'arg2']);
hook.tap('MyPlugin', (arg1, arg2) => {
console.log(`Values received: ${arg1}, ${arg2}`);
});
hook.call('Hello', 'World');
AsyncParallelHook
AsyncParallelHook allows for asynchronous execution of hooks in parallel. It is useful when you have multiple asynchronous tasks that can run at the same time without waiting for each other.
const { AsyncParallelHook } = require('tapable');
const asyncHook = new AsyncParallelHook(['arg1']);
asyncHook.tapPromise('AsyncPlugin', (arg1) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(`Async value: ${arg1}`);
resolve();
}, 1000);
});
});
asyncHook.promise('Hello').then(() => {
console.log('All async plugins have finished.');
});
AsyncSeriesHook
AsyncSeriesHook allows for asynchronous execution of hooks one after another. It is useful when tasks need to be done in a specific sequence, with each task starting only after the previous one has completed.
const { AsyncSeriesHook } = require('tapable');
const asyncSeriesHook = new AsyncSeriesHook(['arg1']);
asyncSeriesHook.tapPromise('AsyncSeriesPlugin', (arg1) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(`Async series value: ${arg1}`);
resolve();
}, 1000);
});
});
asyncSeriesHook.promise('World').then(() => {
console.log('All async series plugins have finished.');
});
EventEmitter3 is a high-performance event emitter. It provides similar functionality to Tapable in that it allows you to emit and listen for events, but it does not offer the same plugin/hook system that Tapable does.
Mitt is a tiny functional event emitter / pubsub. It provides similar event handling capabilities but lacks the hook system that allows for interception and modification of behavior, which is a key feature of Tapable.
RxJS is a library for reactive programming using Observables. It can be used to handle asynchronous data streams and events similar to Tapable's hooks, but it is more focused on functional reactive programming patterns and is more complex.
var Tapable = require("tapable");
Tapable
is a class for plugin binding and applying.
Just extend it.
function MyClass() {
Tapable.call(this);
}
MyClass.prototype = Object.create(Tapable.prototype);
MyClass.prototype.method = function() {};
Or mix it in.
function MyClass2() {
EventEmitter.call(this);
Tapable.call(this);
}
MyClass2.prototype = Object.create(EventEmitter.prototype);
Tapable.mixin(MyClass2.prototype);
MyClass2.prototype.method = function() {};
void apply(plugins: Plugin...)
Attaches all plugins passed as arguments to the instance, by calling apply
on them.
void plugin(names: string|string[], handler: Function)
names
are the names (or a single name) of the plugin interfaces the class provides.
handler
is a callback function. The signature depends on the class. this
is the instance of the class.
void applyPlugins(name: string, args: any...)
Synchronously applies all registered handlers for name
. The handler functions are called with all args.
any applyPluginsWaterfall(name: string, init: any, args: any...)
Synchronously applies all registered handlers for name
. The handler functions are called with the return value of the previous handler and all args. For the first handler init
is used and the return value of the last handler is return by applyPluginsWaterfall
void applyPluginsAsync(
name: string,
args: any...,
callback: (err?: Error) -> void
)
Asynchronously applies all registered handlers for name
. The handler functions are called with all args and a callback function with the signature (err?: Error) -> void
. The handler functions are called in order of registration.
callback
is called after all handlers are called.
any applyPluginsBailResult(name: string, args: any...)
Synchronously applies all registered handlers for name
. The handler function are called with all args. If a handler function returns something !== undefined
, the value is returned and no more handlers are applied.
applyPluginsAsyncWaterfall(
name: string,
init: any,
callback: (err: Error, result: any) -> void
)
Asynchronously applies all registered handlers for name
. The handler functions are called with the current value and a callback function with the signature (err: Error, nextValue: any) -> void
. When called, nextValue
is the current value for the next handler. The current value for the first handler is init
. After all handlers are applied, callback
is called with the last value. If any handler passes a value for err
, the callback
is called with this error and no more handlers are called.
applyPluginsAsyncSeries(
name: string,
args: any...,
callback: (err: Error, result: any) -> void
)
Asynchronously applies all registered handlers for name
. The handler functions are called with all args
and a callback function with the signature (err: Error) -> void
. The handlers are called in series, one at a time. After all handlers are applied, callback
is called. If any handler passes a value for err
, the callback
is called with this error and no more handlers are called.
applyPluginsParallel(
name: string,
args: any...,
callback: (err?: Error) -> void
)
Applies all registered handlers for name
in parallel. The handler functions are called with all args and a callback function with the signature (err?: Error) -> void
. The callback
function is called when all handlers have called the callback without err
. If any handler calls the callback with err
, callback
is invoked with this error and the other handlers are ignored.
applyPluginsParallelBailResult(
name: string,
args: any...,
callback: (err: Error, result: any) -> void
)
Applies all registered handlers for name
in parallel. The handler functions are called with all args and a callback function with the signature (err?: Error) -> void
. Handler functions must call the callback. They can either pass an error, pass undefined, or pass a value. The first result (either error or value) which is not undefined is passed to the callback
. The order is defined by registration, not by the speed of the handler function.
hasPlugins(
name: string
)
Returns true, if plugins are registered for this name.
FAQs
Just a little module for plugins.
The npm package tapable receives a total of 33,852,971 weekly downloads. As such, tapable popularity was classified as popular.
We found that tapable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.